using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Collections.Generic;

namespace CUSTOMS.Modules.QLHS.Components.QLBB
{
    public partial class BienBan
    {
        public void Create(IList<HangHoa> collection)
        {
            this.InsertUpdate();
            HangHoa.DeleteBy_SoToKhai_AND_MaHaiQuan_AND_MaLoaiHinh_AND_NamDangKy(this.SoToKhai, this.MaHaiQuan, this.MaLoaiHinh, this.NamDangKy);
            foreach (HangHoa item in collection)
            {
                item.Insert();
            }
        }

        //public void Create(IList<HangHoa> collection)
        //{
        //    using (TransactionScope scope = new TransactionScope())
        //    {
        //        this.InsertUpdate();
        //        HangHoa.DeleteBy_SoToKhai_AND_MaHaiQuan_AND_MaLoaiHinh_AND_NamDangKy(this.SoToKhai, this.MaHaiQuan, this.MaLoaiHinh, this.NamDangKy);
        //        foreach (HangHoa item in collection)
        //        {
        //            item.Insert();
        //        }
        //        scope.Complete();
        //    }
        //}

        public static DataSet ChuyenTrangThai(int soToKhai, string maHaiQuan, string maLoaiHinh, int namDangKy)
        {
            const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_ChuyenTrangThai]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@SoToKhai", SqlDbType.Int, soToKhai);
            db.AddInParameter(dbCommand, "@MaHaiQuan", SqlDbType.Char, maHaiQuan);
            db.AddInParameter(dbCommand, "@MaLoaiHinh", SqlDbType.Char, maLoaiHinh);
            db.AddInParameter(dbCommand, "@NamDangKy", SqlDbType.Int, namDangKy);

            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet InThongKe(DateTime tuNgay, DateTime denNgay, string loaiHang, string truongHop, string trangThai)
        {
            const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_InThongKe]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@TuNgay", SqlDbType.DateTime, tuNgay);
            db.AddInParameter(dbCommand, "@DenNgay", SqlDbType.DateTime, denNgay);
            db.AddInParameter(dbCommand, "@LoaiHang", SqlDbType.VarChar, loaiHang);
            db.AddInParameter(dbCommand, "@TruongHop", SqlDbType.VarChar, truongHop);
            db.AddInParameter(dbCommand, "@TrangThai", SqlDbType.VarChar, trangThai);

            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet InThongKeDanhMucHangHoa(DateTime tuNgay, DateTime denNgay)
        {
            const string spName = "[dbo].[p_HAIQUAN_QLHS_BienBan_InThongKeDanhMucHangHoa]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@TuNgay", SqlDbType.DateTime, tuNgay);
            db.AddInParameter(dbCommand, "@DenNgay", SqlDbType.DateTime, denNgay);

            return db.ExecuteDataSet(dbCommand);
        }
    }
}
